<?php
// $Id: deadwood.notifies.inc,v 1.1 2008/08/12 17:39:18 solotandem Exp $

/**
 * @file
 * Generate version upgrade code from 5.x to 6.x.
 *
 * The functions in this file match up with the 80 topics in the roadmap at
 * http://drupal.org/node/114774. As the topics sometimes overlap, there is
 * a corresponding redundancy in the functions. The hope for the 7.x version
 * of this module is that the 7.x roadmap will be written without any
 * overlap in topics.
 *
 * This includes 6 topics in the menu API roadmap at
 * http://drupal.org/node/103114.
 *
 * Copyright 2008 by Jim Berry ("solotandem", http://drupal.org/user/240748)
 */

/**
 * Convert calls to format_plural() to allow for variable replacements like t().
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_format_plural(&$file) {
  $hook = 'format_plural';
  $cur = $file;
  $new = $cur;

  $msg = "/* TODO\n" .
         "   An argument for replacements has been added to format_plural(),\n" .
         "   escaping and/or theming the values just as done with t()." .
         "*/";

  $from = array();
  $to = array();
  // format_plural() accepts replacements.
  /* 5.x code:
   * strtr(format_plural($num, 'There is currently 1 %type post on your site.', 'There are currently @count %type posts on your site.'), array('%type' => theme('placeholder', $type)));
   * becomes 6.x code:
   * format_plural($num, 'There is currently 1 %type post on your site.', 'There are currently @count %type posts on your site.', array('%type' => $type));
   */
//  $from[] = '/[\s(]strtr\s*\(format_plural\s*\(.*\),\s*array\(.*=>\s*theme\(.*,(\w)*\)/';
//  $to[] = $msg . '$1'; // We could place the msg at the top of the file with other messages???
//  $from[] = '/format_plural\s*\(/';
//  $to[] = $msg . '$1';
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about new language object.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_locale(&$file) {
  $hook = 'locale';
  $cur = $file;
  $new = $cur;

  // Check for references to locale.
  $pattern = '/$locale/';
  if (!preg_match($pattern, $file, $matches)) {
    return;
  }

  $msg =
"/* TODO locale become language
   With the improved language subsystem in Drupal, the global locale variable
   (which contained a language code) is replaced with the global language object
   (which contains properties for several language details). As with locale,
   the new language object gives information about the language chosen for the
   current page request. This change also affects themes, because Drupal now
   knows about the directionality (left to right or right to left) of the
   language used, and themes can make use of this information to output proper stylesheets. */";

  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about node/add automatic menu generation and alteration.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_node_add(&$file) {
  $hook = 'menu';
  $cur = deadwood_find_hook($hook, $file);
  $new = $cur;
  $hook = 'node_add';

  $msg =
"/* TODO
   The node/add/\$type menu items are now auto-generated by the menu system.
   You should not declare them in your menu hook. This means that you can
   use hook_menu_alter to change the visibility of an item or change the
   access callback. */";

  $from = array();
  $to = array();
  // TODO This is a good reason to combine the changes in the roadmap.
  // This change is dependent on whether other menu changes are done since
  // the path becomes the array index.
  // node/add is now menu generated
  $from[] = "/^(.*\$items.*\'path\'\s*=>\s*\'node\/add\/\w+)/m";
  $to[] = "\n$msg\n\n$1";
  // node/add is now menu generated (if other menu changes are done)
  $from[] = '/^(\s*\$items\[\'node\/add\/\w+\'\]\s*=\s*array\s*\()/m';
  $to[] = "\n$msg\n\n$1";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about new hook_watchdog.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_hook_watchdog(&$file) {
  $hook = 'hook_watchdog';
  $cur = $file;
  $new = $cur;

  $msg =
"/* TODO
   There is a new hook_watchdog in core. This means that contributed modules
   can implement hook_watchdog to log Drupal events to custom destinations.
   Two core modules are included, dblog.module (formerly known as watchdog.module),
   and syslog.module. Other modules in contrib include an emaillog.module,
   included in the logging_alerts module. See syslog or emaillog for an
   example on how to implement hook_watchdog.
function example_watchdog(\$log = array()) {
  if (\$log['severity'] == WATCHDOG_ALERT) {
    mysms_send(\$log['user']->uid,
      \$log['type'],
      \$log['message'],
      \$log['variables'],
      \$log['severity'],
      \$log['referer'],
      \$log['ip'],
      format_date(\$log['timestamp']));
  }
} */";

  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Specify PHP compatibility in .info files. (NOT DONE)
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_info3(&$file) {
//  $hook = 'info3';
//  $cur = $file;
//  $new = $cur;

//  $from = array();
//  $to = array();
//  // Core compatibility now specified in .info files
//  $from[] = '/(dependencies\s*=.*)$/m';
//  $to[] = "$1\ncore = 6.x";
//
//  deadwood_do_conversions($from, $to, $new);
//
//  // New syntax for .info files
//  $search = '/(dependencies)\s*=\s*(.+)/';
//  $callback = 'deadwood_fix_dependencies';
//  $chg = preg_replace_callback($search, $callback, $new);
//  $new = $chg != '' ? $chg : $new;
//
//  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about changes to node_revision_list.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_node_revision_list(&$file) {
  $hook = 'node_revision_list';
  $cur = $file;
  $new = $cur;

  // Check for calls to node_revision_list.
  $pattern = '/node_revision_list\s*\(/';
  if (!preg_match($pattern, $file, $matches)) {
    return;
  }

  $msg =
"/* TODO node_revision_list() now returns keyed array
   In previous versions of core, the node_revision_list() method returned an
   ordered array, but there were no meaningful keys to index the data. If you
   wanted to find information about a specific revision, you had to iterate
   through the whole array until you found the revision ID you were looking for.
   Now, the array is indexed by the revision ID (the vid column from the
   {node_revisions} table) so if you're looking for information about a specific
   revision, you can find it immediately. */";

  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about new user_mail_tokens.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_mail_tokens(&$file) {
  $hook = 'mail_tokens';
  $cur = $file;
  $new = $cur;

  $msg =
"/* TODO New user_mail_tokens() method may be useful.
   user.module now provides a user_mail_tokens() function to return an array
   of the tokens available for the email notification messages it sends when
   accounts are created, activated, blocked, etc. Contributed modules that
   wish to make use of the same tokens for their own needs are encouraged
   to use this function. */";

  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about changes to files table.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_files_table(&$file) {
  $hook = 'files_table';
  $cur = $file;
  $new = $cur;

  // Check for references to {files} table.
  $pattern = '/\{files\}\s*/';
  if (!preg_match($pattern, $file, $matches)) {
    return;
  }

  $msg =
"/* TODO {files} table changed
   The files table has been changed to make it easier to preview uploaded files.
   Two fields, status and timestamp, have been added so that temporary files
   can be stored and cleaned automatically removed during a cron job. Use
   file_set_status() to change a files status and make it a permanent file. */";

  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about displaying node form elements in previews.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_node_preview(&$file) {
  $hook = 'node_preview';
  $cur = $file;
  $new = $cur;

  $msg =
"/* TODO Node previews and adding form fields to the node form.
   There is a subtle but important difference in the way node previews (and other
   such operations) are carried out when adding or editing a node. With the new
   Forms API, the node form is handled as a multi-step form. When the node form
   is previewed, all the form values are submitted, and the form is rebuilt with
   those form values put into \$form['#node']. Thus, form elements that are added
   to the node form will lose any user input unless they set their '#default_value'
   elements using this embedded node object. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about new return value of hook_user.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_hook_user(&$file) {
  $hook = 'user';
  $cur = $file;
  $new = $cur;

  // Check for presence of hook_user function.
  $exists = deadwood_find_hook($hook, $file);
  if ($exists == '') {
    return;
  }

  $msg =
"/* TODO hook_user('view')
   The return value of hook_user('view') has changed, to match the process that
   nodes use for rendering. Modules should add their custom HTML to
   \$account->content element. Further, this HTML should be in the form that
   drupal_render() recognizes. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  $hook = 'hook_user';
  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about changing text of submit buttons.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_submit_buttons(&$file) {
  $hook = 'submit_buttons';
  $cur = $file;
  $new = $cur;

  // Check for presence of submit buttons.
  $pattern = "/'#type'\s*=>\s*'submit'/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Change 'Submit' to 'Save' on buttons
   It has been agreed on that the description 'Submit' for a button is not a
   good choice since it does not indicate what actually happens. While for
   example on node editing forms, 'Preview' and 'Delete' describe exactly what
   will happen when the user clicks on the button, 'Submit' only gives a vague
   idea. When labelling your buttons, make sure that it is clear what this
   button does when the user clicks on it. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about changed parameters for node_feed.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_node_feed(&$file) {
  $hook = 'node_feed';
  $cur = $file;
  $new = $cur;

  // Check for calls to node_feed function.
  $pattern = "/node_feed\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO node_feed() parameters changed
   node_feed() now accepts an array of nids (i.e. integers), and not a database
   result object. this is more flexible for callers but sometimes slighly less
   efficient. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about replacement of submit operation in hook_nodeapi.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_hook_nodeapi(&$file) {
  $hook = 'nodeapi';
  $cur = $file;
  $new = $cur;

  // Check for presence of hook_nodeapi function.
  $exists = deadwood_find_hook($hook, $file);
  if ($exists == '') {
    return;
  }

  // Check for presence of submit operation.
  $pattern = "/'submit'/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  // TODO This could just as easily be a conversion routine.
  // Replace 'submit' with 'presave'.

  $msg =
"/* TODO hook_nodeapi('submit') has been replaced by op='presave'
   There is no longer a 'submit' op for nodeapi. Instead you may use the newly
   created 'presave' op. Note, however, that this op is invoked at the beginning
   of node_save(), in contrast to op='submit' which was invoked at the end of
   node_submit(). Thus 'presave' operations will be performed on nodes that are
   saved programatically via node_save(), while in Drupal 5.x op='submit' was
   only applied to nodes saved via the node form. Note that the node form is now,
   in effect, a multistep form (for example when previewing), so if you need to
   fix up the data in the node for re-building the form, use a #submit function
   added to the node form's \$form array. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  $hook = 'hook_nodeapi';
  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about elimination of db_num_rows function.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_db_num_rows(&$file) {
  $hook = 'db_num_rows';
  $cur = $file;
  $new = $cur;

  // Check for calls to db_num_rows function.
  $pattern = "/db_num_rows\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Remove db_num_rows() method
   The db_num_rows() method was removed from the database abstraction layer in
   6.x core, as it was a database dependent method. Developers need to use other
   handling to replace the needs of this method. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about elimination of $row argument from db_result function.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_row_argument(&$file) {
  $hook = 'row_argument';
  $cur = $file;
  $new = $cur;

  // Check for calls to db_num_rows function.
  // TODO Actual calls to this function may have more complicated argument for
  // first parameter and cause this to find something.
  $pattern = "/db_result\s*\((.+?),\s*(.+?)\)/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Remove \$row argument from db_result() method
   The \$row argument of db_result() was removed from the database abstraction
   layer in 6.x core, as it was a database dependent option. Developers need to
   use other handling to replace the needs of this method. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about not calling node_access_rebuild themselves on enable/disable.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_node_access_rebuild1(&$file) {
  $hook = 'node_access_rebuild';
  $cur = $file;
  $new = $cur;

  // Check for calls to node_access_rebuild function.
  $pattern = "/node_access_rebuild\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Node access modules : simplified hook_enable / hook_disable / hook_node_access_records
   In D5, modules defining node access permissions via hook_node_grants /
   hook_node_access_records had to do a bit of hoop jumping : call
   node_access_rebuild() in their hook_enable / hook_disable, check they're not
   being disabled before actually returning their grants in hook_node_access_records()...
   This is not required in D6 anymore : the system ensures the node grants are
   rebuilt if needed when modules are enabled or disabled. Therefore, node access
   modules should *not* call node_access_rebuild themselves on enable/disable.  */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  $hook = 'node_access_rebuild1';
  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about new batch_mode parameter for node_access_rebuild.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_node_access_rebuild2(&$file) {
  $hook = 'node_access_rebuild';
  $cur = $file;
  $new = $cur;

  // Check for calls to node_access_rebuild function.
  $pattern = "/node_access_rebuild\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO node_access_rebuild(\$batch_mode = TRUE) / node_access_needs_rebuild()
   To avoid PHP timeouts when rebuilding content access permissions (which can
   critically leave the site's content half open), node_access_rebuild() now
   accepts a \$batch_mode boolean parameter (defaults to FALSE), letting it
   operate in 'progressive' mode using the new D6 batch processing (progressbar
   processing, à la update.php).
   See http://api.drupal.org/api/function/node_access_needs_rebuild/6. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  $hook = 'node_access_rebuild2';
  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about book module rewrite.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_book(&$file) {
  $hook = 'book';
  $cur = $file;
  $new = $cur;

  // Check for calls to book module functions.
  $pattern = "/book_\w+.*\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO The book module has been rewritten to use the new menu system
   The book module now makes use of the new Drupal 6.x menu system (e.g. the
   {menu_links} table) to store and render the book hierarchy. Any modules that
   previously interfaced with the book module will need to be re-written. All
   the data loaded onto a node by the book module is now found in the
   \$node->book attribute.

   Many of the book module API function have changed. For example, function
   book_recurse has been removed. For most use cases, this should be replaced by
   book_export_traverse, but it no longer has a \$depth parameter. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about checking node access before emailing content.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_email_node_access(&$file) {
  $hook = 'email_node_access';
  $cur = $file;
  $new = $cur;

  // Check for calls to drupal_mail function.
  $pattern = "/drupal_mail\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Check node access before emailing content
   Modules like Organic Groups and Project Issue send the same content as an
   email notifications to many users. They should now be using the new 3rd
   parameter to node_access() to check access on the content before emailing it.
   Note that db_rewrite_sql() provodes no protection because the recipient is not
   the logged in user who is receiving the content. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}



// INSERT ABOVE



/**
 * Add note about FormAPI image buttons.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_image_buttons(&$file) {
  $hook = 'image_buttons';
  $cur = $file;
  $new = $cur;

  $msg =
"/* TODO FormAPI image buttons are now supported.
   FormAPI now offers the 'image_button' element type, allowing developers to
   use icons or other custom images in place of traditional HTML submit buttons.

\$form['my_image_button'] = array(
  '#type'         => 'image_button',
  '#title'        => t('My button'),
  '#return_value' => 'my_data',
  '#src'          => 'my/image/path.jpg',
); */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about db_last_insert_id.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_db_last(&$file) {
  $hook = 'db_last';
  $cur = $file;
  $new = $cur;

  $msg =
"/* TODO db_next_id() is gone, and replaced as db_last_insert_id()
   Since db_next_id() introduce some problems, and the use of this function
   can be replaced by database level auto increment handling, db_next_id()
   is now gone and replaced as db_last_insert_id() with help of serial type
   under Schema API (check out http://drupal.org/node/149176 for more details).
   Please refer to drupal_write_record() as demonstration. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about new hook_mail implementation.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_hook_mail(&$file) {
  $hook = 'hook_mail';
  $cur = $file;
  $new = $cur;

  // Check for calls to drupal_mail function.
  $pattern = "/drupal_mail\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO New hook_mail implementation
   Because of changes to drupal_mail function, you need to move the variables
   setup and string replace commands into the hook_mail implementation and then
   call drupal_mail with the name of the module which contains this
   implementation, the mailkey, the recipient, the language of the user the mail
   goes to and some arbitrary parameters. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about drupal_set_breadcrumb.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_breadcrumb(&$file) {
  $hook = 'breadcrumb';
  $cur = $file;
  $new = $cur;

  // Check for calls to menu_set_location.
  $pattern = "/menu_set_location/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Use drupal_set_breadcrumb() instead of menu_set_location() to set
   custom breadcrumbs.
   Currently in D5, menu_set_location() is 'misused' in several modules to set
   a custom breadcrumb, drupal_set_breadcrumb() should be used instead, as
   discussed in #177497.
   Note, when using drupal_set_breadcrumb(), you need to include 'home' but
   not the current page.
   Alternatively, if you do want to set the current location in the menu tree
   as well as affect breadcrumbs, use menu_set_item(). */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about Drupal.settings.basePath being automatically added.
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_basePath(&$file) {
  $hook = 'basePath';
  $cur = $file;
  $new = $cur;

  // Check for calls to drupal_add_js function.
  $pattern = "/drupal_add_js\s*\(/";
  if (!preg_match($pattern, $cur, $matches)) {
    return;
  }

  $msg =
"/* TODO Automatically add Drupal.settings.basePath
   In Drupal 5, you would have to add the base path to Drupal.settings yourself
   if you needed it (it's needed for just about every AHAH/AJAX enabled module
   if you did it right). Now in Drupal 6, it's added automatically. You can always
   find it at Drupal.settings.basePath (actually, as soon as drupal_add_js() is
   called at least once, so this is similar to the way we automatically add
   drupal.js and jquery.js. */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}

/**
 * Add note about removal of hook_submit().
 *
 * @param string $file The file to convert.
 */
function deadwood_convert_hook_submit(&$file) {
  $cur = $file;
  $new = $cur;

  // Check for presence of hook_node_info function.
  $hook = 'node_info';
  $exists = deadwood_find_hook($hook, $file);
  if ($exists == '') {
    return;
  }

  $msg =
"/* TODO hook_submit() has been removed
   In Drupal 5.x, hook_submit() allowed node modules to alter the node before
   saving it to the database (it was run between hook_validate() and
   hook_insert()/hook_update()). In Drupal 6.x this hook has been removed.
   Instead, you should attach a submit handler to the form created in hook_form(),
   and then alter the \$form_state['values'] array as needed.
   A submit handler would look like:
   \$form['#submit'] = array('mymodule_node_form_submit_handler'); */";

  $from = array();
  $to = array();
  // Find the Id line in the file.
  $from[] = '/^(\/\/ \$Id.*\$\s*$)/m';
  $to[] = "$1\n$msg\n";

  $hook = 'hook_submit';
  deadwood_do_conversions($from, $to, $new);
  deadwood_save_changes($cur, $new, $file, $hook);
}
